<template>
  <div class="file-list">
    <div class="file-header">
      <h3>文件列表</h3>
      <span class="file-count">共2个</span>
    </div>
    
    <div class="file-items">
      <div 
        v-for="file in files" 
        :key="file.id"
        :class="['file-item', { active: file.id === activeFileId }]"
        @click="selectFile(file.id)"
      >
        <div class="file-icon">
          <el-icon><Document /></el-icon>
        </div>
        <div class="file-info">
          <div class="file-name">{{ file.name }}</div>
          <div class="file-date">{{ file.date }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { Document } from '@element-plus/icons-vue'

/**
 * 文件信息接口
 */
interface FileInfo {
  id: string
  name: string
  date: string
}

// 文件列表数据
const files = ref<FileInfo[]>([
  {
    id: '1',
    name: '2022-05-24_15_07_32-房屋买卖合同.pdf',
    date: '2023-04-05 14_44_30'
  },
  {
    id: '2', 
    name: '2023-04-05 14_44_30',
    date: '2023-04-05 14_44_30'
  }
])

// 当前选中的文件ID
const activeFileId = ref<string>('1')

/**
 * 选择文件
 * @param fileId 文件ID
 */
const selectFile = (fileId: string) => {
  activeFileId.value = fileId
}
</script>

<style scoped>
.file-list {
  padding: 20px;
}

.file-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.file-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.file-count {
  font-size: 12px;
  color: #909399;
}

.file-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.file-item:hover {
  background-color: #f5f7fa;
}

.file-item.active {
  background-color: #e6f7ff;
  border-color: #409eff;
}

.file-icon {
  margin-right: 12px;
  color: #409eff;
  font-size: 20px;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 14px;
  color: #303133;
  margin-bottom: 4px;
  word-break: break-all;
  line-height: 1.4;
}

.file-date {
  font-size: 12px;
  color: #909399;
}
</style>